
## Function for obtaining robust standard errors -------
robust_se <- function(some_reg, some_method) {
  coeftest(some_reg, vcov = vcovHC(some_reg, type = some_method))
} 

# Clustered standard errors 
cluster_se <- function(some_reg, cluster_var) {
  vcov_var <- cluster.vcov(some_reg, formula(paste("~", cluster_var)))
  results <- coeftest(some_reg, vcov_var)
  return(results)
} 

## Function to obtain adjusted R2 from robust se
get_adj_r <- function(some_regression){
  round(summary(some_regression)$adj.r.squared, 3)
}

## Function to obtain sample size from robust se
get_obs <- function(some_reg) {
  length(summary(some_reg)$residuals)
}


## Function to extract information from Linear Hypothesis test:
race_score_linear_test <- function(regression, race_inter) {
  # regression = result_same_race_bi[[1]][[3]]
  # race_inter = "negro_na"
  
  teste_paste <- paste0(race_inter, ":grades_score + grades_score = 0")
  teste_results <- linearHypothesis(regression, c(teste_paste), vcov = hccm)
  return(c(teste_results$F[2], teste_results$`Pr(>F)`[2]))
}

